<?php
class content_form {
	var $modelid;
	var $fields;
	var $contentid;

    function __construct($modelid) {
        $db = xt_load('db','icweb');
		$this->db = &$db;
		$this->modelid = $modelid;
		$this->fields = xt_readcache('fields_'.$this->modelid.'.cache.php', MS_CACHEPATH.'model/');
    }

	/*function content_form($modelid) {
		$this->__construct($modelid);
	}*/

	function get($data = array()) {
		if(isset($data['contentid'])) $this->contentid = $data['contentid'];
		$info = array();
		$this->content_url = $this->content_url = xt_hashmap($data,'url');
		foreach($this->fields as $field=>$v) {
		    if($v['iscore']) continue;
			$func = $v['formtype'];
			
			$value = isset($data[$field]) ? htmlspecialchars($data[$field], ENT_QUOTES) : '';
			if($func=='pages' && isset($data['maxcharperpage'])) {
				$value = $data['paginationtype'].'|'.$data['maxcharperpage'];
			}
			$form = $this->$func($field, $value, $v);
			if($form !== false) {
			    if($func=='editor') {
			        $star = $v['minlength'] || $v['pattern'] ? 1 : 0;
                    $info['editor'][$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star);
                    continue;
			    }
				if($v['isbase']) {
                    $star = $v['minlength'] || $v['pattern'] ? 1 : 0;
                    $info['base'][$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star);
                } else {
                    $star = $v['minlength'] || $v['pattern'] ? 1 : 0;
                    $info['senior'][$field] = array('name'=>$v['name'], 'tips'=>$v['tips'], 'form'=>$form, 'star'=>$star);
                }
			}
		}
		return $info;
	}
}?>